package com.cuckoo.mall.thus.order.addorder;

import com.bgn.baseframe.base.BasePresenterImpl;
import com.bgn.baseframe.network.HttpObserver;
import com.bgn.baseframe.network.bean.TDataBean;
import com.bgn.baseframe.utils.UiUtil;
import com.cuckoo.mall.R;
import com.cuckoo.mall.javabean.CreateOrderParms;
import com.cuckoo.mall.javabean.OrderResult;
import com.cuckoo.mall.javabean.Ticket;
import com.cuckoo.mall.network.ApiManager;

import java.util.List;


/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class AddorderPresenter extends BasePresenterImpl<AddorderContract.View> implements AddorderContract.Presenter {

    @Override
    public void createOrder(CreateOrderParms parms) {
        ApiManager.createOrder(parms).subscribe(new HttpObserver<TDataBean<OrderResult>>(mView) {
            @Override
            public void onSucceed(TDataBean<OrderResult> value) {
                if (value.getData() != null) {
                    mView.whenCreateOrderSucceed(value.getData());
                }
            }
        });
    }

    @Override
    public void createOrderByProduc(CreateOrderParms parms) {
        ApiManager.createOrderByProduc(parms).subscribe(new HttpObserver<TDataBean<OrderResult>>(mView) {
            @Override
            public void onSucceed(TDataBean<OrderResult> value) {
                if (value.getData() != null) {
                    mView.whenCreateOrderSucceed(value.getData());
                }
            }
        });
    }

    @Override
    public void checkTicketInfo() {
        ApiManager.getAllTickets().subscribe(new HttpObserver<TDataBean<List<Ticket>>>(mView) {
            @Override
            public void onSucceed(TDataBean<List<Ticket>> value) {
                if (value.getData() != null && value.getData().size() > 0) {
                    mView.whenGetTicketInfo(value.getData().get(0));
                }
            }

            @Override
            public void onDefeat(TDataBean<List<Ticket>> value) {
                super.onDefeat(value);
                // mView.initFaild(value.getError_msg());
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                //mView.initFaild(UiUtil.getString(R.string.server_error));
            }
        });
    }
}
